const path = require('path')
const { merge } = require('webpack-merge')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const common = require('./webpack.common')

module.exports = merge(common, {
  mode: 'development',
  devServer: {
    contentBase: path.join(__dirname, 'dist'), // html所在路径
    compress: true, // 是否压缩
    port: 3000, // 端口
    hot: true, // 热部署
    open: true // 打包完成后自动打开网页
  },
  devtool: 'eval-cheap-module-source-map',
  module: {
    rules: [
      {
        test: /\.js$/,
        use: 'eslint-loader',
        exclude: file => (
          /node_modules/.test(file) &&
                    !/\.vue\.js/.test(file)
        ),
        enforce: 'pre' // 先执行找个
      }
    ]
  },
  plugins: [
    new CopyWebpackPlugin({
      patterns: [
        {
          from: path.join(__dirname, 'public'),
          to: 'public'
        },
        {
          from: path.join(__dirname, 'assets'),
          to: 'assets'
        }
      ]
    })
  ]
})
